package org.example.com.exception;

import org.example.com.util.JsonResult;
import org.example.com.util.RecultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

// 负责处理全局异常信息 类似于catch块
@RestControllerAdvice
public class GlbalExcption {
    //负责处理sql异常
    @ExceptionHandler(SQLException.class)
    public JsonResult  sqlException(Throwable e){
        return RecultTool.fail(500, e.getMessage());
    }
    @ExceptionHandler(userSaveException.class)
    public JsonResult userSaveException(Throwable e){
        return RecultTool.fail(5001, e.getMessage());
    }
    @ExceptionHandler(userRemoveException.class)
    public JsonResult userRemoveException(Throwable e){
        return RecultTool.fail(5002, e.getMessage());
    }
    @ExceptionHandler(userUpdateException.class)
    public JsonResult userUpdateException(Throwable e){
        return RecultTool.fail(5003, e.getMessage());
    }
    @ExceptionHandler(passwordNotExicts.class)
    public JsonResult passwordNotExistsException(Throwable e) {
        return RecultTool.fail(5006, e.getMessage());
    }
    @ExceptionHandler(UsernamePassowrdException.class)
    public JsonResult usernamePassowrdException(Throwable e) {
        return RecultTool.fail(5090, e.getMessage());
    }
    @ExceptionHandler(NotLoginException.class)
    public JsonResult notLoginException(Throwable e) {
        return RecultTool.fail(5091, e.getMessage());
    }


}
